package top.zerozoo.learn.grade.servlet;

import top.zerozoo.learn.grade.factory.ServiceFactory;
import top.zerozoo.learn.grade.service.CourseScoreService;
import top.zerozoo.learn.grade.service.StudentService;
import top.zerozoo.learn.grade.util.NumberUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/scoreRemove.do")
public class ScoreRemoveServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String[] id = req.getParameterValues("id");
        if (id == null) {
            resp.getWriter().print("fail");
            return;
        }
        for (int i = 0; i < id.length; i++) {
            int _id = NumberUtils.parse(id[i], Integer.class, -1);
            if (_id < 0) {
                continue;
            }
            ServiceFactory.get(CourseScoreService.class).delete(_id);
        }
        resp.getWriter().print("success");

    }

}
